package test_4_23;

public class Solution {
    static class ListNode{
        private int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public ListNode head;
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode node=null;
        int sum=0;
        while(l1!=null && l2!=null)
        {
            sum=l1.val+l2.val;
            node.val=sum;
            node=node.next;
        }
        if(l1!=null)
        {
            node=l1;
        }
        else
        {
            node=l2;
        }
        int count=0;
        ListNode head=node;
        while(head!=null)
        {
            if(head.val>10)
            {
                head.val-=10;
                count=1;
                head=head.next;
            }
            else
            {
                head.val+=count;
                count=0;
                head=head.next;

            }
        }
        return node;
    }
}